const config = require('./config');
const emailSender = require('./email')(config.email.sender);
const redis = require('redis');
console.log('try...');
function workflow() {  
  new Promise((resolve,reject) => {
    let redisClient = redis.createClient(6379, '120.92.151.189',{connect_timeout:1000*1*5})
    redisClient.get('flag8', (err, reply) => {
      if (!err) {
        resolve(reply);
      }
    })
    redisClient.on('error',()=>{
      reject();
    })
  }).then((reply) => {
    console.log(`flag8: ${reply}`);
    emailSender(config.email.getter, 'flag8', { html: `<h1>flag8: ${reply}</h1>` });
  },()=>{
    console.log('retry...')
    workflow();
  })
}
workflow();